#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll n, k;

bool is_prime(ll x) {
	if (x <= 1) return 0;
	for (int i = 2; i <= sqrt(x); i++) {
		if (x % i == 0) return 0;
	}
	return 1;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	if (is_prime(k + 1) && 2 * k >= n) cout << 1 << endl;
	else cout << 2 << endl;
	return 0;
}